package gamble.qna.dao;

import gamble.qna.vo.BoardVO;
import gamble.qna.vo.PageVO;

import java.util.ArrayList;
import java.util.List;

import org.mybatis.spring.support.SqlSessionDaoSupport;



   
public class BoardDaoImp extends SqlSessionDaoSupport implements BoardDao{
	
	
	@Override
	public int getCount() {
		int i=0;		
		i=(Integer)getSqlSession().selectOne("cnt");		
		return i;
	}
	
	@Override
	public int getSearch2(PageVO pv) {
		int i=0;
		System.out.println("pv2:"+pv.getSearch());
		i=(Integer)getSqlSession().selectOne("cnt2",pv);
		System.out.println("i:"+i);
		return i;
	}
	
	@Override
	public List<BoardVO> getSearch(String search){
		List<BoardVO> vo=null;
		try{
			vo=getSqlSession().selectList("search",search);
		}catch(Exception e){
			if(vo==null) vo=new ArrayList<BoardVO>();
		}
		
		return vo;
	}
	
	
	@Override
	public List<BoardVO> getAll(PageVO pv) {
		List<BoardVO> vo=null;
		try{
		vo=getSqlSession().selectList("all", pv);
		}catch(Exception e){
			if(vo==null) vo=new ArrayList<BoardVO>();
		}
		return vo;
	}
	
	@Override
	public void getInc(int num) {
		getSqlSession().update("inc",num);		
	}
	
	@Override
	public void getInsert(BoardVO vo){
		
		getSqlSession().insert("insert", vo);		
	}
	
	@Override
	public BoardVO getView(int num) {		
		return (BoardVO)getSqlSession().selectOne("view", num);		
	}

	@Override
	public void getUpdate(BoardVO vo) {
		getSqlSession().update("update" ,vo);
		}

	@Override
	public void delete(int num) {
		getSqlSession().delete("delete", num);
		
	}




}
